package screenmanager;

import java.awt.DisplayMode;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;

import animation.Animation;

public class BuckySM {

	
	public static void main(String[] args) {
		BuckySM b = new BuckySM();
		b.run();
	}
	
	private Animation a;
	private ScreenManager s;
	private Image bg;
	
	private static final DisplayMode modes[] = {
		new DisplayMode(800, 600, 32, 0),
		new DisplayMode(800, 600, 24, 0),
		new DisplayMode(800, 600, 16, 0),
		new DisplayMode(640, 480, 32, 0),
		new DisplayMode(640, 480, 24, 0),
		new DisplayMode(640, 480, 16, 0),
		new DisplayMode(1024, 768, 16, 0),
	};
	
	public void loadImages(){
		bg = new ImageIcon("img/bg.jpg").getImage();
		Image f1 = new ImageIcon("img/f1.jpg").getImage();
		Image f2 = new ImageIcon("img/f2.jpg").getImage();
		
		a = new Animation();
		a.addScene(f1, 250);
		a.addScene(f2, 250);
	}
	
	public void run(){
		s = new ScreenManager();
		try{
			DisplayMode dm = s.findFirstCompatibleMode(modes);
			s.setFullScreen(dm);
			loadImages();
			movieLoop();
		}finally{
			s.restoreScreen();
		}
	}
	public void movieLoop(){
		long startingTime = System.currentTimeMillis();
		long cumTime = startingTime;
		while(cumTime - startingTime < 6000){
			long timePassed = System.currentTimeMillis() - cumTime;
			cumTime += timePassed;
			a.update(timePassed);
			
			Graphics2D g = s.getGraphics();
			draw(g);
			g.dispose();
			s.update();
			
			try{
				Thread.sleep(20);
			}catch(Exception e){}
		}
	}
	
	
	public void draw(Graphics g){
		g.drawImage(bg,0,0,1024,768,null);
		g.drawImage(a.getImage(),0,0,50,50,null);
	}
	
	
}
